<!DOCTYPE html>
<html lang="en">

	<head>
		<meta http-equiv="content-type" content="text/html; charset=UTF-8">
		<meta charset="utf-8">
		<title></title>
		<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
		<meta name="description" content="">
		<meta name="author" content="">
		<!-- STYLESHEETS -->
		<!--[if lt IE 9]><script src="../../js/flot/excanvas.min.js"></script><script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script><script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
		<link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
		<link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
		<link rel="stylesheet" type="text/css" href="../../css/responsive.css">
		<link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
	    <!-- file-input -->
	    <link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css" />
		<!-- SELECT2 -->
	<link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css" />
		<!-- datatable -->
		<link rel="stylesheet" href="../../js/datatables/datatable.css">
		 <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
	<!-- JQUERY -->
		<script src="../../js/jquery/jquery-2.0.3.min.js"></script>
		<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
		<script src="../../js/common.js"></script>
	</head>

	<body>
		<header class="navbar clearfix" id="header">
		</header>
		<!-- PAGE -->
		<section id="page">
			<!-- SIDEBAR -->
			<div id="sidebar" class="sidebar">
				<div class="sidebar-menu nav-collapse">

					<!-- SIDEBAR MENU -->
					<ul>
						

					</ul>
					<!-- /SIDEBAR MENU -->
				</div>

			</div>
			<!-- /SIDEBAR -->
			<div id="main-content">
				<!-- SAMPLE BOX CONFIGURATION MODAL FORM-->
				<div class="modal fade" id="box-config" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-dialog">
					<form id="form_Images">
						<div class="modal-content">
							<div class="modal-header">
								<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
								<h4 class="modal-title">维护图片</h4>
							</div>
							<div class="modal-body">								
								
								<input type="hidden" name="id">
								<div class="form-group  mrg-bt10 ">
											<label class="control-label col-md-3"><span class="required">*</span>图片类型：</label>
											<div class="col-md-6" style="text-align: left">
												<select id="ImagesType1_select" class="col-md-6 select2-offscreen" tabindex="-1">												
												<option value="QuantityCheck">质检报告</option>
												<option value="Size">尺码</option>												
												</select>											
											</div>
								</div>
								
								<div class="form-group  mrg-bt10" style="height: 100px">
									<label class="control-label col-md-3" style="line-height:34px;"><span class="required">*</span>图片：</label>
									<form>
									<div class="col-md-8">									
                                      	<div hidden-image></div>
								          	<div class="fileinput fileinput-new" data-provides="fileinput" >
									          	<div class="image_preview_list" style="float:left;" id="imgs">
									          		<div class="fileinput-preview thumbnail image_preview_default" data-trigger="fileinput" style="width: 120px; height: 90px;"></div>	          		                           	
												</div>
												<div style="float:left; margin-left:5px; padding-top:23px;" class="addnewimg" id="f_span">
													<span class="btn btn-default btn-file" id="fir">
														<span class="fileinput-new" id="two" >上传图片</span>		
														<span class="fileinput-exists">Change</span>												
															<input type="file" name="uploadFile" upload-file="imageUrlProduct">
													</span>
													<div class="progress progress-striped active" role="progressbar" aria-valuemin="0" aria-valuemax="100" style=" margin-bottom: 0px;margin-top:10px;">
													<div class="progress-bar progress-bar-success" style="width:0%;"></div>
												    </div>	
												</div>
												
											</div>
																		 								
																	
									</div>
								</form>	
						
							</div>
							</div>
							<div class="modal-footer">
								<button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
								<button type="button" class="btn btn-primary bt-save">保存</button>
							</div>
						</div>
						</form>
						
					</div>
				</div>
				<!-- /SAMPLE BOX CONFIGURATION MODAL FORM-->
				<div class="container">
					<div class="row">
						<div id="content" class="col-lg-12">
							<!-- PAGE HEADER-->
							<div class="row" style="height: 30px;">
								<div class="col-sm-12">
									<div class="page-header">
										<!-- STYLER -->

										<!-- /STYLER -->
										<!-- BREADCRUMBS -->
										<ul class="breadcrumb">
											<li>
												<i class="fa fa-home"></i>
												<a href="../index.html">首页</a>
											</li>
											<li>
												<a href="#">商品管理</a>
											</li>
											<li>商品品牌</li>
										</ul>
										<!-- /BREADCRUMBS -->

									</div>
								</div>
							</div>
							<!-- /PAGE HEADER -->
							<!-- FORMS QUERY-->
							<div class="row">
								<div class="col-md-12">
									<div class="row">
										<div class="col-md-12">
										
											<div class="box border primary">
												<div class="box-title">
													<h4><i class="fa fa-bars"></i>查询条件</h4>
												</div>
												<div class="box-body big" style="padding:10px;">
													<form class="form-horizontal" role="form">
														<div class="form-group mrg-bt10">
															
																<label class="control-label col-sm-2" style="line-height:34px;">图片类型：</label>
															<div class="col-md-3">
																<select id="ImagesType_select" class="col-md-7 select2-offscreen" tabindex="-1">												
																		<option value="-1">选择类型</option>
																		<option value="QuantityCheck">质检报告</option>
																		<option value="Size">尺码</option>															
																		</select>	
															</div>														
															<div class="col-sm-1">
																<a class="btn btn-primary search">查询</a>
															</div>
														</div>
													</form>
												</div>
											</div>
										</div>
									</div>
								</div>
							</div>
							<!-- /FORMS QUERY -->
							<div class="row" style="height: 30px;">
								<div class="col-md-12">
									<div class="box ">
										<a id="create" data-toggle="modal" class="btn btn-success config">
											<i class="fa  fa-plus-square-o"></i> 新增图片
										</a>
										
									</div>
								</div>
							</div>

							<div class="row">
								<!-- TABLES -->
								<div class="col-md-12">
									<!-- BOX -->
									<div class="box border primary">
										<div class="box-title">
											<h4><i class="fa fa-table"></i>列表</h4>

										</div>
										<div class="box-body">
											<table id="db_Images_list" cellpadding="0" cellspacing="0" border="0" class="datatable table table-striped table-bordered table-hover">
												
											</table>
										</div>
									</div>
									<!-- /BOX -->
								</div>
							</div>
							<!-- /TABLES -->

							<div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
							</div>
						</div>
						<!-- /CONTENT-->
					</div>
				</div>
			</div>
			<input type="hidden" name="ImagesId" />
		</section>

		<!--/PAGE -->
		<!-- JAVASCRIPTS -->
		<!-- Placed at the end of the document so the pages load faster -->
	
		<!-- JQUERY UI-->
		<script src="../../js/jquery-ui-1.10.3.custom/js/jquery-ui-1.10.3.custom.min.js"></script>
		<!-- BOOTSTRAP -->
		<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

		<!-- BLOCK UI -->
		<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
		
		<!-- AUTOSIZE -->
		<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
	
		<!-- INPUT MASK -->
		<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>
		<!-- SELECT2 -->
		<script type="text/javascript" src="../../js/select2/select2.min.js"></script>
	   
	     <!-- bootstrap-fileupload -->
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.iframe-transport.js"></script>
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload.min.js"></script>
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-process.min.js"></script> 
	    <script type="text/javascript" src="../../js/jquery-upload/js/jquery.fileupload-validate.min.js"></script>
	    
		<!-- UNIFORM -->
		<script type="text/javascript" src="../../js/uniform/jquery.uniform.min.js"></script>
		<!-- spinner -->
		<script src="../../js/spinner/spin.js"></script>
		<!-- DATA TABLES -->
		<script type="text/javascript" src="../../js/datatables/bootstrap-select.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-bootstrap.js"></script>
		<script type="text/javascript" src="../../js/datatables/datatable-tabletools.js"></script>
		<script type="text/javascript" src="../../js/datatables/fnAddTr.js"></script>

		<!--bootbox-->
		<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
		<!-- COOKIE -->
		<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
		<!-- CUSTOM SCRIPT -->
		<script src="../../js/script.js"></script>
		
	
		<script>
		
		var Images=function(){
	         //保存编辑
	         var saveImages=function(){	        
	            $(".form-group").removeClass("has-error");
	           		
					if($(".image_preview_default").find("img").length==0){
					    $("#image_preview_list").parents(".form-group").addClass("has-error");
						return false;
					}				
					
						var images = {};
						images.id = $("input[name=id]").val();
						images.imagePath=$(".image_preview_default").find("img").attr("src");
						images.tags=$("#ImagesType1_select").val();
					
						$.ajax({
							type: "post",
							url: App.getContextPath()+"admin/images/saveImages.do",
							async: true,
							data: $.param({images:JSON.stringify(images)}),
							success: function(result) {
							  $("#box-config").modal("hide");
							  
								searchImages();
							}
						});
					
				
	         };
	         
	         var deleteImages=function(){
	          		var pid=$(this).attr("pid");
							$.confirm("确认删除此图片?",function(){
								$.ajax({
										type: "post",
										url: App.getContextPath()+"admin/images/updateImages.do",
										async: true,
										data: {
											id: pid
										},
										success: function(result) {
											$.alert("操作成功");
											searchImages();
										}
						});
								
					});
	         };
	         
	         var searchImages=function(){
	               var url=App.getContextPath()+"admin/images/searchImages.do";	
	               var type=$("#ImagesType_select").val();
	              
	               if(type!=-1&&type!=null)
	                  url+="?q="+type;
		           var dtSetting = $.dataTableSetting({					
							"ajaxSource" :url,
							"serverSide" : true,
							"bFilter" : false,// 去掉搜索框
							"bLengthChange" : true,// 每页显示数量	
						
							"sScrollX":"100%",
							"sScrollXInner": "100%",
							"iDisplayLength": 25,
							
							"bSort" : false,					
							"aoColumns" : [ {
								"mDataProp" : "id",
								"sTitle" : "图片ID",
								"width" : "10%",
								"class":"id"			
							}, {
								"mDataProp" : "tags",
								"sTitle" : "图片类型",
								"class":"tags",
								"render":function(data, type, row){		
									if(row.tags=="QuantityCheck")
										return "质检报告";
									return row.tags;
															   
								}
							}, {						
								"sTitle" : "图片",
								"class":"imagePath",	
								"render":function(data, type, row){							
								    return "<a target='_blank' href='"+row.imagePath+"'><img width='30px' height='30px' src="+(row.imagePath)+"></a>";
								}
							}	
							, {
								"mDataProp" : "createTime",
								"sTitle" : "创建时间",
								"render":function(data, type, row){
								    return $.getLocalTime(row.createTime);
								}
							}, {						
								"sTitle" : "操作",
								"width" : "20%",
								"render":function(data, type, row) {
							     var str="<button class='btn btn-success btn-xs bt_edit btn-width'><i class='fa fa-pencil-square-o'></i>编辑</button>";
							      str+="<button class='btn btn-danger btn-xs bt_del btn-width' pid='"+row.id+"' style='margin-left:5px'><i class='fa fa-trash-o'></i> 删除</button>";
								 return str;
								}
							}]
						});
					
				      $mainDataTable = $("#db_Images_list").dataTable(dtSetting);
	         };
	         var showDialog=function(){
	              fileUpLoad();
	             
	              $(".fileinput-preview>img").remove();
	                       
	             $(".bt-save").unbind("click").click(saveImages);
	             $("#box-config").modal("show");
	         };
	         
	         var fileUpLoad=function(){	  
	         		$(".progress").hide();       	
					$("[upload-file=imageUrlProduct]").fileupload({
						url: App.getContextPath()+"admin/file/uploadImage.do",
						formData: {fileType: "ProductDetailImage"},
						dataType: 'json',
						acceptFileTypes: /(\.|\/)(gif|jpe?g|png|JPG?g)$/i,
						iframe: true,
					    start:function(e) {		    	
					    	$('.progress').fadeIn(300);					    	
					    	return true;
				    		},
						autoUpload: true,
						done: function(e, data) {
							var result = data.result;	
							if(result.message!=""){
								$.alert(result.message);							
								return false;
							}else{
																	
					    	var $tr = $(this).closest("form");					    	
					    	$tr.find("[hidden-image]").append("<input type='hidden' name='imagePath' value='" + result.fileUrl+"' />");
					    	$tr.find(".image_preview_default").html("<img src='"+result.fileUrl+"' />");			
							}
						},						
					    progressall: function (e, data) {					    	
				            var progress = parseInt(data.loaded / data.total * 100, 10);
				            $('.progress .progress-bar').css('width',progress + '%');
				        }
					}).on('fileuploaddone',function(e,data) {
							$(".progress").fadeOut(300);
					
					});
				
	         };
	         
	         return {
	         
	         init:function(){
	        	 $("#ImagesType_select").select2({placeholder: "选择类型"});
	        	 $("#ImagesType1_select").select2({placeholder: "选择类型"});
	             searchImages();
	             $(".search").click(searchImages);
	           
	         	 $("#db_Images_list").on("click",".bt_edit",function() {
	         	    showDialog();
					var tr = $(this).closest("tr");		
					$("#ImagesType_select").select2("val",$(tr).find(".tags").html());
					$("#box-config").find("input[name=id]").val($(tr).find(".id").html());					
					$(".image_preview_default").html("<img src='"+$(tr).find(".imagePath").find("img").attr("src")+"'>");
					$("[hidden-image]").append("<input type='hidden' value='"+$(tr).find(".imagePath").find("img").attr("src")+"' name='logo'>");
					$("#box-config").modal("show");
				});
	         
	          $("#db_Images_list").on("click",".bt_del",deleteImages);
	          	
	          $("#create").click(showDialog);
	          }
		    }
	      }();
	      
	      $(function(){
	      $("#header").load("../head.html");
	        App.init(); //Initialise plugins and elements
	      	Images.init();
	      	
	      });
		</script>
		<!-- /JAVASCRIPTS -->
	</body>

</html>